package com.demo.alf;


import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRExporter;
import net.sf.jasperreports.engine.JRExporterParameter;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
import net.sf.jasperreports.engine.export.JRXlsExporter;
import net.sf.jasperreports.engine.export.JRXlsExporterParameter;

public class demoRep {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Persona p=null;
		List<Persona> list=new ArrayList<Persona>();
		
		for (int i = 0; i < 20; i++) {
			p=new Persona();
			p.setDni("545454"+i);
			p.setApellidos("AAAA BBB "+i);
			p.setNombre("XXXX YYYY " +i);
			list.add(p);
		}
		//llamar al reporte
//		String rutaImagenLogo = "";
//		String rutaReporte = "/view/reportes/rptConsultaGestor.jasper";
//		InputStream reportConsultaGestorSt = getResourceInputStream(rutaReporte);
//		InputStream imgLogoSt = getResourceInputStream(rutaImagenLogo);
		HashMap<String, Object> paramReport = new HashMap<String, Object>();
		paramReport.put("pTituloRep", "Listado Personas");
//		paramReport.put("P_REPORT", reportConsultaGestorSt);
		JRBeanCollectionDataSource dataSource = new JRBeanCollectionDataSource(list);
		try {
			
			JasperPrint jasperPrint = JasperFillManager.fillReport("repPersona1.jasper", paramReport, dataSource);
			System.out.println("Paso!!!!!!!");
			JRExporter exporter = null;
			//PrintWriter out = null;
			OutputStream output = null;
			output = new FileOutputStream(new File("Pesona.xls"));
			exporter = new JRXlsExporter();
			exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
			exporter.setParameter(JRXlsExporterParameter.IS_DETECT_CELL_TYPE, Boolean.TRUE);
			exporter.setParameter(JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.TRUE);
			exporter.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE);
			exporter.setParameter(JRXlsExporterParameter.OUTPUT_STREAM, output);
			exporter.exportReport();
		
		} catch (JRException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

}
